package com.lanjiu.lib.imclient.dto.notify;

import com.lanjiu.pro.business.BusinessProtocolEntities;
import com.lanjiu.lib.imclient.dto.FriendDto;
import com.lanjiu.lib.imclient.dto.base.Dto;
import com.lanjiu.lib.imclient.ims.IMSContacts;

/**
 * @description: 好友通知
 * @author: Panwei
 * @date: 2019/11/14 21:55
 */
public class FriendNotifyDto extends Dto {

    // 申请状态(申请/拒绝申请/同意申请)
    private int status;

    // 好友实体
    private FriendDto friend;

    // 留言
    private String leaveMessage;

    public FriendNotifyDto() {
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public FriendDto getFriend() {
        return friend;
    }

    public void setFriend(FriendDto friend) {
        this.friend = friend;
    }

    public String getLeaveMessage() {
        return leaveMessage;
    }

    public void setLeaveMessage(String leaveMessage) {
        this.leaveMessage = leaveMessage;
    }

    public FriendNotifyDto(BusinessProtocolEntities.TouristsFriendNotify friendNotify) {
        this.status = friendNotify.getStatus();
        this.friend = new FriendDto(friendNotify.getFriend());
        this.leaveMessage = friendNotify.getLeaveMessage();
    }

    public FriendNotifyDto(BusinessProtocolEntities.RegisteredFriendNotify friendNotify) {
        this.status = friendNotify.getStatus();
        this.friend = new FriendDto(friendNotify.getFriend());
        this.leaveMessage = friendNotify.getLeaveMessage();
    }

    @Override
    public Object toProtobuf() {
        if (IMSContacts.UserType.REGISTERED_USER.equals(friend.getCurrentUserType())) {
            BusinessProtocolEntities.RegisteredFriendNotify.Builder builder = BusinessProtocolEntities.RegisteredFriendNotify.newBuilder();
            builder.setStatus(status);
            if (null != friend)
                builder.setFriend((BusinessProtocolEntities.RegisteredFriend) friend.toProtobuf());
            if (null != leaveMessage) builder.setLeaveMessage(leaveMessage);
            return builder.build();
        } else {
            BusinessProtocolEntities.TouristsFriendNotify.Builder builder = BusinessProtocolEntities.TouristsFriendNotify.newBuilder();
            builder.setStatus(status);
            if (null != friend)
                builder.setFriend((BusinessProtocolEntities.TouristsFriend) friend.toProtobuf());
            if (null != leaveMessage) builder.setLeaveMessage(leaveMessage);
            return builder.build();
        }
    }
}
